
#include <d3dx9.h>
#include "dxutil.h"
#include "EventList.h"

CEventList::~CEventList()
{
	Clear();
}

void CEventList::Clear()
{
	m_ColorList.clear();
	m_ScaleList.clear();
	m_FactorList.clear();
	m_PosList.clear();
	return;
}

void CEventList::AddToList(const float& fTickNum, const D3DXCOLOR& color)
{
	m_ColorList.push_back(make_pair(fTickNum, color));
}

void CEventList::AddToList(const float& fTickNum, const D3DXVECTOR3& vScale)
{
	m_ScaleList.push_back(make_pair(fTickNum, vScale));
}

void CEventList::AddToPosList(const float& fTickNum, const D3DXVECTOR3& vPos)
{
	m_PosList.push_back(make_pair(fTickNum, vPos));
}
//
void CEventList::AddToList(const float& fTickNum, const float& fFactor)
{
	m_FactorList.push_back(make_pair(fTickNum, fFactor));
}


D3DXCOLOR CEventList::GetColor(const float& fTickNum)
{
	vector<COLORNODE>::iterator it;
	it = m_ColorList.begin();
    if(it == m_ColorList.end()) return D3DXCOLOR(1.0F, 1.0F, 1.0F, 1.0F);

	while(1)
	{
		if(it == m_ColorList.end()) break;
		if((it + 1) == m_ColorList.end()) break;

		if((it + 1)->first > fTickNum)
		{
			D3DXCOLOR colorDelta = ((it + 1)->second - it->second) /
				                   ((it + 1)->first - it->first);

			D3DXCOLOR colorCur = it->second;
			colorCur = colorCur + (colorDelta * (fTickNum - it->first));
			return colorCur;
		}
		++it;
	}
	return D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f);
}

D3DXVECTOR3 CEventList::GetScale(const float& fTickNum)
{
    vector<SCALENODE>::iterator it;
	it = m_ScaleList.begin();

	while(1)
	{
		if(it == m_ScaleList.end()) break;
		if((it + 1) == m_ScaleList.end()) break;

		if((it + 1)->first > fTickNum)
		{
			D3DXVECTOR3 vScaleDelta = ((it + 1)->second - it->second) /
				                   ((it + 1)->first - it->first);

			D3DXVECTOR3 vScaleCur = it->second;
			vScaleCur = vScaleCur + (vScaleDelta * (fTickNum - it->first));
			return vScaleCur;
		}
		++it;
	}
	return D3DXVECTOR3(1.0f, 1.0f, 1.0f);
}

D3DXVECTOR3 CEventList::GetPos(const float& fTickNum)
{
    vector<SCALENODE>::iterator it;
	it = m_PosList.begin();

	while(1)
	{
		if(it == m_PosList.end()) break;
		if((it + 1) == m_PosList.end()) break;

		if((it + 1)->first > fTickNum)
		{
			D3DXVECTOR3 vPosDelta = ((it + 1)->second - it->second) /
				                   ((it + 1)->first - it->first);

			D3DXVECTOR3 vPosCur = it->second;
			vPosCur = vPosCur + (vPosDelta * (fTickNum - it->first));
			return vPosCur;
		}
		++it;
	}
	return D3DXVECTOR3(1.0f, 1.0f, 1.0f);
}

float CEventList::GetFactor(const float& fTickNum)
{
    vector<FLOATFACTOR>::iterator it;
	it = m_FactorList.begin();

	while(1)
	{
		if(it == m_FactorList.end()) break;
		if((it + 1) == m_FactorList.end()) break;

		if((it + 1)->first > fTickNum)
		{
			float fFactorDelta = ((it + 1)->second - it->second) /
				                   ((it + 1)->first - it->first);

			float fFactorCur = it->second;
			fFactorCur = fFactorCur + (fFactorDelta * (fTickNum - it->first));
			return fFactorCur;
		}
		++it;
	}
	return (0.0f);
}


